import * as koffi from 'koffi'
import { app } from 'electron'
import * as path from 'path'
import * as os from 'os'

// Function to initialize the DLL
export default (): void => {
  try {
    // Check if running on Windows
    if (os.platform() === 'win32') {
      // Resolve the path to the DLL relative to the app's resources directory
      const dllPath = path.join(app.getAppPath(), 'resources', 'termb.dll')
      const lib = koffi.load(dllPath)

      // Initialize the DLL functions
      const InitComm = lib.func('int _stdcall InitComm(int Port)')
      console.log('Successfully loaded termb.dll:', InitComm)
    } else {
      // Handle non-Windows platforms
      console.log('termb.dll is only supported on Windows. Current platform:', os.platform())
    }
  } catch (error) {
    console.error('Failed to load termb.dll:', error)
  }
}
